package com.corecloud.security.oauth;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.corecloud.entity.SysAppEntity;
import com.corecloud.service.SysAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.NoSuchClientException;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


/**
 * 数据库获取第三方平台客户端信息
 */
@Service
public class ClientDetailsServiceImp  implements ClientDetailsService {


	@Autowired
	private SysAppService sysAppService;

	
	@Override
	public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
		SysAppEntity app =  sysAppService.selectOne(new QueryWrapper<SysAppEntity>().eq("client_id",clientId));
		if (app == null) {
			throw new NoSuchClientException(String.format("clientId %s 不存在!", clientId));
		}
		ClientDetails clientDetails = new ClientDetailsImp(app);
		return clientDetails;
	}

}
